package com.example.common.base;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.common.CommonPresenter;
import com.example.common.ICommonModel;
import com.example.common.ICommonView;

public abstract  class BaseMvpFragment<M extends ICommonModel>  extends Fragment implements ICommonView {
    private M m;
    private CommonPresenter presenter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(setLayoutId(), container, false);

        return view ;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        m = setModel();
       if (m!=null)presenter = new CommonPresenter(this, m);
        setUpView();
        setUpData();
    }

    public abstract int setLayoutId();

    public abstract void setUpView();

    public abstract void setUpData();

    public abstract M setModel();
}
